/*------------------------------------------------------------------------------
 
Project: Mathisen, R.M., Schakel, W., Hense, S., Elsässer, L., Persson, M. and
	Pontusson, J. (forthcoming). 'Unequal Responsiveness and Government
	Partisanship in Northwest Europe,' in Lupu, N. and Pontusson, J. (eds)
	Unequal Democracies: Public Policy, Responsiveness, and Redistribution in an
	Era of Rising Economic Inequality. Cambridge: Cambridge University Press.

Note: This do-file performs the analyses presented in the tables of the main
	text and supplementary appendix.

Data: mshepp_data (see mshepp_01_prep do-file for original sources)

Last updated: 1 May 2023

Sections:
	1. Main text
	2. Supplementary appendix

------------------------------------------------------------------------------*/

* This is where the pooled dataset is stored
global mshepp_data "YOUR/PATH/HERE"

* Loading in the data
use "$mshepp_data/mshepp_data.dta", clear

/*------------------------------------------------------------------------------
 1. Main text
------------------------------------------------------------------------------*/

* Table 1: Survey items by country
table c, c(n year min year max year mean surveytype)

* Table 2: Descriptive statistics
tabstat polchange2 p10 p50 p90 diff9010 diff9050 diff5010 leftgov2, by(c)	///
	s(mean sd) format(%3.2f)

* Table 3: Preference gaps > 0.1
reg polchange2 p10 i.c if diff9010_abs > .1 [pw = weight_d9010], vce(robust)
reg polchange2 p90 i.c if diff9010_abs > .1 [pw = weight_d9010], vce(robust)
reg polchange2 p50 i.c if diff9050_abs > .1 [pw = weight_d9050], vce(robust)
reg polchange2 p90 i.c if diff9050_abs > .1 [pw = weight_d9050], vce(robust)

* Table 4: Difference measures
foreach m in table_4 table_4_pval {
	matrix `m' = J(3, 5, .)
	matrix rownames `m' = P90-P10 P90-P50 P50-P10
	matrix colnames `m' = Pooled DE NL NO SE
}

local counter = 1

foreach v of varlist diff9010 diff9050 diff5010 {
	reg polchange2 `v' p50 i.c [pw = weight], vce(robust)
	matrix m`v' = r(table)
	matrix table_4[`counter', 1] = m`v'[1, 1]
	matrix table_4_pval[`counter', 1] = m`v'[4, 1]

	forval c = 1/4 {
		reg polchange2 `v' p50 if c == `c', vce(robust)
		matrix m`v'`c' = r(table)
		matrix table_4[`counter', `=`c'+1'] = m`v'`c'[1, 1]
		matrix table_4_pval[`counter', `=`c'+1'] = m`v'`c'[4, 1]
	}

	local ++counter
}

matrix list table_4, f(%4.3f) // coefficients
matrix list table_4_pval, f(%4.3f) // p-values

* Table 5: P90-P10 preferences x left government
reg polchange2 c.diff9010##c.leftgov2 p50 i.c [pw = weight], vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 i.c if c2 != "Norway" [pw = weight], vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 if c == 1, vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 if c == 2, vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 if c == 3, vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 if c == 4, vce(robust)

* Table 6: P90-P50 preferences x left government
reg polchange2 c.diff9050##c.leftgov2 p50 i.c [pw = weight], vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 i.c if c2 != "Norway" [pw = weight], vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 if c == 1, vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 if c == 2, vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 if c == 3, vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 if c == 4, vce(robust)

* Table 7: Difference measures (economic issues only)
foreach m in table_7 table_7_pval {
	matrix `m' = J(3, 5, .)
	matrix rownames `m' = P90-P10 P90-P50 P50-P10
	matrix colnames `m' = Pooled DE NL NO SE
}

local counter = 1

foreach v of varlist diff9010 diff9050 diff5010 {
	reg polchange2 `v' p50 i.c if dim == 1 [pw = weight], vce(robust)
	matrix m`v' = r(table)
	matrix table_7[`counter', 1] = m`v'[1, 1]
	matrix table_7_pval[`counter', 1] = m`v'[4, 1]

	forval c = 1/4 {
		reg polchange2 `v' p50 if dim == 1 & c == `c', vce(robust)
		matrix m`v'`c' = r(table)
		matrix table_7[`counter', `=`c'+1'] = m`v'`c'[1, 1]
		matrix table_7_pval[`counter', `=`c'+1'] = m`v'`c'[4, 1]
	}

	local ++counter
}

matrix list table_7, f(%4.3f) // coefficients
matrix list table_7_pval, f(%4.3f) // p-values

/*------------------------------------------------------------------------------
 2. Supplementary appendix
------------------------------------------------------------------------------*/

* Table A1: Bivariate associations (two-year window)
foreach m in table_a1 table_a1_pval {
	matrix `m' = J(3, 5, .)
	matrix rownames `m' = P90-P10 P90-P50 P50-P10
	matrix colnames `m' = Pooled DE NL NO SE
}

local counter = 1

forval v = 10(40)90 {
	reg polchange2 p`v' i.c [pw = weight], vce(robust)
	matrix m`v' = r(table)
	matrix table_a1[`counter', 1] = m`v'[1, 1]
	matrix table_a1_pval[`counter', 1] = m`v'[4, 1]

	forval c = 1/4 {
		reg polchange2 p`v' if c == `c', vce(robust)
		matrix m`v'`c' = r(table)
		matrix table_a1[`counter', `=`c'+1'] = m`v'`c'[1, 1]
		matrix table_a1_pval[`counter', `=`c'+1'] = m`v'`c'[4, 1]
	}

	local ++counter
}

matrix list table_a1, f(%4.3f) // coefficients
matrix list table_a1_pval, f(%4.3f) // p-values

* Table A2: Bivariate associations (four-year window)
foreach m in table_a2 table_a2_pval {
	matrix `m' = J(3, 5, .)
	matrix rownames `m' = P90-P10 P90-P50 P50-P10
	matrix colnames `m' = Pooled DE NL NO SE
}

local counter = 1

forval v = 10(40)90 {
	reg polchange4 p`v' i.c if c2 != "United States" [pw = weight], vce(robust)
	matrix m`v' = r(table)
	matrix table_a2[`counter', 1] = m`v'[1, 1]
	matrix table_a2_pval[`counter', 1] = m`v'[4, 1]

	forval c = 1/4 {
		reg polchange4 p`v' if c == `c', vce(robust)
		matrix m`v'`c' = r(table)
		matrix table_a2[`counter', `=`c'+1'] = m`v'`c'[1, 1]
		matrix table_a2_pval[`counter', `=`c'+1'] = m`v'`c'[4, 1]
	}

	local ++counter
}

matrix list table_a2, f(%4.3f) // coefficients
matrix list table_a2_pval, f(%4.3f) // p-values

* Table A3: Models with multiple income groups
reg polchange2 p10 p90 i.c [pw = weight], vce(robust)
reg polchange2 p50 p90 i.c [pw = weight], vce(robust)
reg polchange2 p10 p50 i.c [pw = weight], vce(robust)
reg polchange2 p10 p50 p90 i.c [pw = weight], vce(robust)

* Table A4: Difference measure P90-P10, full regression results
reg polchange2 diff9010 p50 i.c [pw = weight], vce(robust)
reg polchange2 diff9010 p50 if c == 1, vce(robust)
reg polchange2 diff9010 p50 if c == 2, vce(robust)
reg polchange2 diff9010 p50 if c == 3, vce(robust)
reg polchange2 diff9010 p50 if c == 4, vce(robust)

* Table A5: Difference measure P90-P50, full regression results
reg polchange2 diff9050 p50 i.c [pw = weight], vce(robust)
reg polchange2 diff9050 p50 if c == 1, vce(robust)
reg polchange2 diff9050 p50 if c == 2, vce(robust)
reg polchange2 diff9050 p50 if c == 3, vce(robust)
reg polchange2 diff9050 p50 if c == 4, vce(robust)

* Table A6: Difference measure P50-P10, full regression results
reg polchange2 diff5010 p50 i.c [pw = weight], vce(robust)
reg polchange2 diff5010 p50 if c == 1, vce(robust)
reg polchange2 diff5010 p50 if c == 2, vce(robust)
reg polchange2 diff5010 p50 if c == 3, vce(robust)
reg polchange2 diff5010 p50 if c == 4, vce(robust)

* Table A7: Coalition analysis, full regression results
reg polchange2 p10 i.c if coal9050 == 1 [pw = weight_coal], vce(robust)
reg polchange2 p50 i.c if coal9050 == 1 [pw = weight_coal], vce(robust)
reg polchange2 p90 i.c if coal9050 == 1 [pw = weight_coal], vce(robust)
reg polchange2 p10 i.c if coal5010 == 1 [pw = weight_coal], vce(robust)
reg polchange2 p50 i.c if coal5010 == 1 [pw = weight_coal], vce(robust)
reg polchange2 p90 i.c if coal5010 == 1 [pw = weight_coal], vce(robust)

* Table A8: P90-P10 preferences x left government, four-year window
reg polchange4 c.diff9010##c.leftgov4 p50 i.c [pw = weight], vce(robust)
reg polchange4 c.diff9010##c.leftgov4 p50 i.c if c2 != "Norway" [pw = weight], vce(robust)
reg polchange4 c.diff9010##c.leftgov4 p50 if c == 1, vce(robust)
reg polchange4 c.diff9010##c.leftgov4 p50 if c == 2, vce(robust)
reg polchange4 c.diff9010##c.leftgov4 p50 if c == 3, vce(robust)
reg polchange4 c.diff9010##c.leftgov4 p50 if c == 4, vce(robust)

* Table A9: P90-P50 preferences x left government, four-year window
reg polchange4 c.diff9050##c.leftgov4 p50 i.c [pw = weight], vce(robust)
reg polchange4 c.diff9050##c.leftgov4 p50 i.c if c2 != "Norway" [pw = weight], vce(robust)
reg polchange4 c.diff9050##c.leftgov4 p50 if c == 1, vce(robust)
reg polchange4 c.diff9050##c.leftgov4 p50 if c == 2, vce(robust)
reg polchange4 c.diff9050##c.leftgov4 p50 if c == 3, vce(robust)
reg polchange4 c.diff9050##c.leftgov4 p50 if c == 4, vce(robust)

* Table A10: P90-P10 preferences x left government, dummy for left government
reg polchange2 c.diff9010##i.leftcat p50 i.c if excl == 0 [pw = weight_excl], vce(robust)
reg polchange2 c.diff9010##i.leftcat p50 i.c if c2 != "Norway" & excl == 0 [pw = weight_excl], vce(robust)
reg polchange2 c.diff9010##i.leftcat p50 if c == 1 & excl == 0, vce(robust)
reg polchange2 c.diff9010##i.leftcat p50 if c == 2 & excl == 0, vce(robust)
reg polchange2 c.diff9010##i.leftcat p50 if c == 3 & excl == 0, vce(robust)
reg polchange2 c.diff9010##i.leftcat p50 if c == 4 & excl == 0, vce(robust)

* Table A11: P90-P50 preferences x left government, dummy for left government
reg polchange2 c.diff9050##i.leftcat p50 i.c if excl == 0 [pw = weight_excl], vce(robust)
reg polchange2 c.diff9050##i.leftcat p50 i.c if c2 != "Norway" & excl == 0 [pw = weight_excl], vce(robust)
reg polchange2 c.diff9050##i.leftcat p50 if c == 1 & excl == 0, vce(robust)
reg polchange2 c.diff9050##i.leftcat p50 if c == 2 & excl == 0, vce(robust)
reg polchange2 c.diff9050##i.leftcat p50 if c == 3 & excl == 0, vce(robust)
reg polchange2 c.diff9050##i.leftcat p50 if c == 4 & excl == 0, vce(robust)

* Table A12: P50-P10 preferences x left government
reg polchange2 c.diff5010##c.leftgov2 p50 i.c [pw = weight], vce(robust)
reg polchange2 c.diff5010##c.leftgov2 p50 i.c if c2 != "Norway" [pw = weight], vce(robust)
reg polchange2 c.diff5010##c.leftgov2 p50 if c == 1, vce(robust)
reg polchange2 c.diff5010##c.leftgov2 p50 if c == 2, vce(robust)
reg polchange2 c.diff5010##c.leftgov2 p50 if c == 3, vce(robust)
reg polchange2 c.diff5010##c.leftgov2 p50 if c == 4, vce(robust)

* Table A13: P90-P10 preferences, economic issues only
reg polchange2 diff9010 p50 i.c if dim == 1 [pw = weight_dim], vce(robust)
reg polchange2 diff9010 p50 if c == 1 & dim == 1, vce(robust)
reg polchange2 diff9010 p50 if c == 2 & dim == 1, vce(robust)
reg polchange2 diff9010 p50 if c == 3 & dim == 1, vce(robust)
reg polchange2 diff9010 p50 if c == 4 & dim == 1, vce(robust)

* Table A14: P90-P50 preferences, economic issues only
reg polchange2 diff9050 p50 i.c if dim == 1 [pw = weight_dim], vce(robust)
reg polchange2 diff9050 p50 if c == 1 & dim == 1, vce(robust)
reg polchange2 diff9050 p50 if c == 2 & dim == 1, vce(robust)
reg polchange2 diff9050 p50 if c == 3 & dim == 1, vce(robust)
reg polchange2 diff9050 p50 if c == 4 & dim == 1, vce(robust)

* Table A15: P50-P10 preferences, economic issues only
reg polchange2 diff5010 p50 i.c if dim == 1 [pw = weight_dim], vce(robust)
reg polchange2 diff5010 p50 if c == 1 & dim == 1, vce(robust)
reg polchange2 diff5010 p50 if c == 2 & dim == 1, vce(robust)
reg polchange2 diff5010 p50 if c == 3 & dim == 1, vce(robust)
reg polchange2 diff5010 p50 if c == 4 & dim == 1, vce(robust)

* Table A16: P90-P50 preferences x left government, economic issues only
reg polchange2 c.diff9050##c.leftgov2 p50 i.c if dim == 1 [pw = weight_dim], vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 if dim == 1 & c == 1, vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 if dim == 1 & c == 2, vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 if dim == 1 & c == 3, vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 if dim == 1 & c == 4, vce(robust)

* Table A17: P90-P10 preferences x left government, economic issues only
reg polchange2 c.diff9010##c.leftgov2 p50 i.c if dim == 1 [pw = weight_dim], vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 if dim == 1 & c == 1, vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 if dim == 1 & c == 2, vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 if dim == 1 & c == 3, vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 if dim == 1 & c == 4, vce(robust)

* Table A18: Changes over time
reg polchange2 c.diff9050##c.leftgov2 p50 i.c if post97 == 0 & dim == 1 [pw = weight_dim], vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 i.c if post97 == 1 & dim == 1 [pw = weight_dim], vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 i.c if post97 == 0 & dim == 2 [pw = weight_dim], vce(robust)
reg polchange2 c.diff9050##c.leftgov2 p50 i.c if post97 == 1 & dim == 2 [pw = weight_dim], vce(robust)

reg polchange2 c.diff9010##c.leftgov2 p50 i.c if post97 == 0 & dim == 1 [pw = weight_dim], vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 i.c if post97 == 1 & dim == 1 [pw = weight_dim], vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 i.c if post97 == 0 & dim == 2 [pw = weight_dim], vce(robust)
reg polchange2 c.diff9010##c.leftgov2 p50 i.c if post97 == 1 & dim == 2 [pw = weight_dim], vce(robust)
